home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1996 September / JCSM Shareware Collection (JCS Distribution) (September 1996).ISO / bother__ / cenvid.zip / CENVIDOS.ZIP / SCRNSAVE.BAT < prev    next >
DOS Batch File  |  1994-10-06  |  3KB  |  99 lines

  1. @echo off
  2. REM *****************************************************
  3. REM *** ScrnSave.bat - Save screen contents to a file ***
  4. REM *** ver.2                                         ***
  5. REM *****************************************************
  6.  
  7. CEnviD %0.bat %1 %2
  8. GOTO CENVI_EXIT
  9.  
  10. #include <Screen.lib>
  11.  
  12. main(argc,argv)
  13. {
  14.    if ( argc != 2  ||  !strcmpi(argv[1],"/?")  ||  !strcmpi(argv[1],"/help") )
  15.       Instructions();
  16.    else {
  17.       ScreenLines = ReadScreen();
  18.       WriteScreenLines(ScreenLines,argv[1]);
  19.    }
  20. }
  21.  
  22. Instructions()
  23. {
  24.    printf("\a\n")
  25.    printf("ScrnSave - Save current ASCII screen to a file\n")
  26.    printf("\n")
  27.    printf("SYNTAX: ScrnSave <FileSpec>\n")
  28.    printf("\n")
  29.    printf("Where: FileSpec - Name of a file to capture screen to; if file then screen is\n")
  30.    printf("                  appended to current file, else file is created\n")
  31.    printf("\n")
  32.    printf("\n")
  33.    printf("Example: SCRNSAVE SCR.TXT\n")
  34.    printf("\n")
  35. }
  36.  
  37. ReadScreen()   // read in each line of the screen; clean lines so that
  38. {              // 0 are blanks, no extra columns, and no extra lines, 1 at least
  39.    ScreenWidth = ScreenSize().col;
  40.    ScreenHeight = ScreenSize().row;
  41.  
  42.    // Read in each row
  43.    BiggestValidRow = 0;
  44.  
  45.    RawScreenData = GetScreenData();
  46.    for ( row = 0; row < ScreenHeight; row++ ) {
  47.       memcpy(ScreenData[row],RawScreenData + row * ScreenWidth,ScreenWidth);
  48.       CleanupScreenLine(ScreenData[row],ScreenWidth);
  49.       if ( ScreenData[row][0] )
  50.          BiggestValidRow = row;
  51.    }
  52.  
  53.    // end this buffer at biggest valid row
  54.    SetArraySpan(ScreenData,BiggestValidRow);
  55.    return ScreenData;
  56. }
  57.  
  58. CleanupScreenLine(pLine,pWidth)  // remove attribute, replace 0 with ' '
  59. {                                // and no extra ' ' at end
  60.    pLine[pWidth] = '\0';
  61.  
  62.    // Turn all 0 into ' '
  63.    while ( lNullChar = memchr(pLine,'\0',pWidth) )
  64.       lNullChar[0] = ' ';
  65.  
  66.    // Put a NULL character following the last non-blank character
  67.    // Find first non-blank character
  68.    lStr = pLine;
  69.    for (;;) {
  70.       // find next non-blank character
  71.       if ( !(lNextStr = lStr + strspn(lStr," "))[0] ) {
  72.          lStr[0] = '\0';
  73.          break;   // found end of string, so lStr is at final blank
  74.       }
  75.       // now at a non-blank, so go to next blank
  76.       if ( !(lStr = strchr(lNextStr,' ')) )
  77.          break;
  78.    }
  79. }
  80.  
  81. WriteScreenLines(ScreenData,FileSpec) // write screen to file
  82. {
  83.    if ( !(fp = fopen(FileSpec,"at")) ) {
  84.       printf("\aUnable to open file \"%s\" for appending.\n",FileSpec);
  85.       abort();
  86.    }
  87.  
  88.    LineCount = 1 + GetArraySpan(ScreenData);
  89.  
  90.    // Read in each row
  91.    for ( row = 0; row < LineCount; row++ )
  92.       fprintf(fp,"%s\n",ScreenData[row]);
  93.  
  94.    fclose(fp);
  95. }
  96.  
  97.  
  98. :CENVI_EXIT
  99.